IF(MSVC)
    MACRO(get_WIN32_WINNT version)
        IF(WIN32 AND CMAKE_SYSTEM_VERSION)
            SET(ver ${CMAKE_SYSTEM_VERSION})
            STRING(REPLACE "." "" ver ${ver})
            STRING(REGEX REPLACE "([0-9])" "0\\1" ver ${ver})

            SET(${version} "0x${ver}")
        ENDIF()
    ENDMACRO()
    
    get_WIN32_WINNT(ver)
    ADD_DEFINITIONS(-D_WIN32_WINNT=${ver})
ENDIF()

IF(ZPSOE_SHAREDLIB)
    ADD_DEFINITIONS("-DZPSOE_SHAREDLIB")
ENDIF()

SET(SRC_LIST 
    zerrno.cxx
    zexception.cxx
    zalgorithm/zarray.cxx
    zalgorithm/zdomain.cxx
    zalgorithm/zdouble.cxx
    zalgorithm/zint.cxx
    zalgorithm/zip.cxx
    zalgorithm/zpath.cxx
    zalgorithm/zrandom.cxx
    zalgorithm/zstring.cxx
    zalgorithm/ztime.cxx
    zalgorithm/zunit.cxx
    zlog.cxx
    zcmd.cxx
    zfilesys.cxx
    zproc.cxx
)

IF(ZPSOE_SHAREDLIB)
    ADD_LIBRARY(${ZPSOE_LIB_NAME} SHARED ${SRC_LIST})
ELSE()
    ADD_LIBRARY(${ZPSOE_LIB_NAME} STATIC ${SRC_LIST})
ENDIF()

IF(MSVC)
    TARGET_LINK_LIBRARIES(${ZPSOE_LIB_NAME} ws2_32 Iphlpapi Netapi32)
ENDIF()

INSTALL(TARGETS ${ZPSOE_LIB_NAME}
    LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
    ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
    RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
)

INSTALL(DIRECTORY ../include/${ZPSOE_LIB_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
